import { Injectable, ElementRef } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { delay } from "rxjs/operators";
import { zip, Observable } from "rxjs";
import { environment } from "src/environments/environment";
declare let d3: any;
// "TableName","Id","TableNo","TableIndex"
export const renameNodesProperties = (d) => {
  return {
    id: d.Id,
    label: d.Label,
  };
};
export const renameTablesProperties = (d) => {
  return {
    id: d.Id,
    label: d.TableName,
    tableNo: d.TableNo,
    tableIndex: d.TableIndex,
  };
};
export const renameEdgesProperties = (d) => {
  return {
    source: d.Source,
    target: d.Target,
    weight: +d.Weight,
  };
};
@Injectable({
  providedIn: "root",
})
export class NetworkGraphService {
  constructor(private http: HttpClient) {}
  getNodes() {
    // return d3.csv("/assets/nodes.csv", renameNodesProperties);
    return d3.csv(
      environment.production
        ? "/jxstjh-zhishu/dist/assets/csv/tables.csv"
        // ? "/dist/assets/csv/tables.csv"
        : "/assets/csv/tables.csv",
      renameTablesProperties
    );
  }
  getEdges() {
    // return d3.csv("/assets/edges.csv", renameEdgesProperties);
    return d3.csv(
      environment.production
        ? "/jxstjh-zhishu/dist/assets/csv/edges.csv"
        // ? "/dist/assets/csv/edges.csv"
        : "/assets/csv/edges.csv",
      renameEdgesProperties
    );
  }
  getData() {
    return Promise.all([this.getNodes(), this.getEdges()]);
  }
}
